package com.huasoft.servlet.userself;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.huasoft.dao.PageCondition;
import com.huasoft.dao.UserFileDao;
import com.huasoft.domain.User;
import com.huasoft.domain.UserFile;

public class ListUserFileByUserIdServlet {

	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setAttribute("listUserFiles", null);
		String status = request.getParameter("status");
		PageCondition pageCondition = new PageCondition();
		if (request.getParameter("page") == null) {
			pageCondition.setPage(1);
		} else {
			status = new String(status.getBytes("iso8859-1"), "gbk");
			Integer page = Integer.valueOf(request.getParameter("page"));
			pageCondition.setPage(page);
		}
		System.out.println(status);
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		UserFileDao userfileDao = new UserFileDao();
		List<UserFile> userfiles = userfileDao.listUserFileByUserId(status,
				pageCondition, user);
		userfileDao.totalPageByUserId(status, pageCondition, user);
		request.setAttribute("status", status);
		request.setAttribute("listUserFiles", userfiles);
		request.setAttribute("totalPage", pageCondition.getTotalPage());
		request.setAttribute("page", pageCondition.getPage());
		request.getRequestDispatcher("/userself/userself_backfile.jsp").forward(request,
				response);
	}

}
